<template>
  <div>
    <div class="pvTop1">
      <router-link :to="{path:'/main/sitedetail'}">
        <div class="pvTop1_1">
          <van-icon name="arrow-left" />
        </div>
      </router-link>
      <div class="gridTop1_2"><img src="../assets/gridicon.png" alt="feedin"></div>
      <div class="pvTop1_3">{{$t('Feedin')}}</div>
      <div class="grid_meter" v-if="isMeter">
        <div class="gridTop1_4">
          <van-icon size="20" color="#CC1207" name="warning-o" />
        </div>
        <div class="gridTop1_5">{{$t('LostMeter')}}</div>
      </div>
    </div>
    <div class="pvBox">
      <div class="pvBox1">
        <div class="pvBox1_1">{{$t('GridPower')}}</div>
        <div class="gridBox1_2">{{resData.realtimepower | numFilter(1,'W')}}</div>
      </div>
      <div class="pvBox2">
        <div class="pvBox1_1">{{$t('ConsumeEnergy')}}</div>
        <div class="gridBox1_2">{{resData.consumeenergy | numFilter(1,'kWh')}}</div>
      </div>
      <div class="pvBox2">
        <div class="pvBox1_1">{{$t('FeedInEnergy')}}</div>
        <div class="gridBox1_2">{{resData.feedinenergy | numFilter(1,'kWh')}}</div>
      </div>
    </div>
  </div>
</template>

<script>
import moment from 'moment'

export default {
  data(){
    return {
      siteId:localStorage.getItem('siteId'),
      tokenId:localStorage.getItem('tokenId'),
      isMeter:false,
      resData:{},
      fifteenRefresh:null
    }
  },
  methods: {
    async getInverterMeterState(){
      let res = await this.API.getInverterMeterState(localStorage.getItem("domain"),{
        'tokenId':this.tokenId,
        'siteId':this.siteId
      });
      if(res.result.meter1ComState == 0 && res.result.meter2ComState == 0){
        this.isMeter = true;
      }
    },
    async getGridData(){
      this.comm.loadingShow();
      let res = await this.API.getGridData(localStorage.getItem("domain"),{
        'tokenId':this.tokenId,
        'siteId':this.siteId,
        'today':moment(new Date()).format('YYYY-MM-DD')
      });
      this.resData = res.result;
    }
  },
  mounted() {
    this.getInverterMeterState();
    this.getGridData();
    this.fifteenRefresh=setInterval(()=>{
      this.getInverterMeterState();
      this.getGridData();
    },900000);
  },
  destroyed(){
    clearInterval(this.fifteenRefresh);
    this.fifteenRefresh=null;
  }
}
</script>

<style scoped lang="less">
.pvTop1{
  background: url("../assets/gridtop.png") no-repeat center  / 100% 100%;
  width: 100%;
  height: 150px;
  box-sizing: border-box;
}
.pvTop1_1{
  font-size: 30px;
  color: #FFFFFF;
  float: left;
  padding: 40px 16px 0 20px;
}
.gridTop1_2{
  float: left;
  padding-top: 30px;
  img{
    width: 40px;
  }
}
.pvTop1_3{
  font-size: 25px;
  font-weight: bolder;
  color: #FFFFFF;
  float: left;
  padding: 39px 0 0 10px;
}
.pvBox{
  position: absolute;
  top:95px;
  width: 100%;
  margin: 0 auto;
  padding:0 25px 10px 25px;
  box-sizing: border-box;
}
.pvBox1{
  height: 130px;
  width: 100%;
  background: url("../assets/kw.png") no-repeat center / 100% 100%;
  border-radius: 5px;
  box-sizing: border-box;
}
.pvBox1_1{
  width: 100%;
  padding: 20px;
  color: #3B3D4E;
  font-size: 16px;
  text-align: left;
  box-sizing: border-box;
}
.gridBox1_2{
  width: 100%;
  padding: 10px 0 0 20px;
  font-size: 28px;
  color: #7ECEF4;
  text-align: left;
  box-sizing: border-box;
}
.pvBox2{
  height: 130px;
  width: 100%;
  background: url("../assets/kwh.png") no-repeat center / 100% 100%;
  border-radius: 5px;
}
.grid_meter{
  float: right;
  padding: 40px 11px 0 13px;
}
.gridTop1_4{
  float: left;
}
.gridTop1_5{
  float: left;
  padding: 1px 0 0 8px;
  color: #CC1207;
  white-space: nowrap;
}
</style>
